<template>
  <div class="box-body">
    <div class="form-group">
      <label class="col-sm-2 control-label">所属部门</label>
      <div class="col-sm-4">
        <Depart ref='depart' :selectedDepart='queryData.depart' @departchanged="val => this.queryData.depart = val"></Depart>
      </div>
      <label for="inputUserName" class="col-sm-2 control-label">姓名</label>
      <div class="col-sm-4">
        <input type="text" class="form-control" id="inputUserName" v-model="queryData.name" placeholder="姓名">
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-2 control-label">证件</label>
      <div class="col-sm-4">
        <input type="text" class="form-control" id="queryCert" v-model="queryData.idCard" placeholder="身份证">
      </div>
      <label class="col-sm-2 control-label">民族</label>
      <div class="col-sm-4">
        <National :withUnlimit='true' :selectedNational="queryData.national" @nationnalchange="val => this.queryData.national = val"></National>
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-2 control-label">移动电话</label>
      <div class="col-sm-4">
        <input type="text" class="form-control" id="phone" v-model="queryData.phone" placeholder="移动电话">
      </div>
      <label class="col-sm-2 control-label">办公电话</label>
      <div class="col-sm-4">
        <input type="text" class="form-control" id="tel" v-model="queryData.tel" placeholder="办公电话">
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-2 control-label">出生年月</label>
      <div class="col-sm-4">
        <MyDatePicker v-bind:date='queryData.birtFrom' @timeChanged="time => this.queryData.birtFrom = time" ref="birthFrom"></MyDatePicker>
      </div>
      <label class="col-sm-2 control-label">到</label>
      <div class="col-sm-4">
        <MyDatePicker ref="birthTo" v-bind:date='queryData.birtTo' @timeChanged="time => this.queryData.birtTo = time"></MyDatePicker>
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-2 control-label">籍贯</label>
      <div class="col-sm-4">
        <Birthplace :withUnlimit='true' v-bind:birthplace="queryData.birthplace"></Birthplace>
      </div>
      <label class="col-sm-2 control-label">性别</label>
      <div class="col-sm-4">
        <select class="form-control" v-model="queryData.sex">
          <option value="-1">不限</option>
          <option value="1">男</option>
          <option value="0">女</option>
        </select>
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-2 control-label">用工性质</label>
      <div class="col-sm-4">
        <WorkType :withUnlimit='true' :selectedworktype="queryData.workType" @worktypechange="val => queryData.workType = val"></WorkType>
      </div>
      <!-- <label class="col-md-2 control-label my-label">在职状态</label>
      <div class="col-md-4">
        <EmployeeStatus :withUnlimit='true' :selectedEmployeeState="queryData.empState" @empstatechange="val => queryData.empState = val"></EmployeeStatus>
      </div> -->
      <label class="col-sm-2 control-label">岗位类型</label>
      <div class="col-sm-4">
        <select class="form-control" v-model="queryData.postType">
          <option v-for="option in this.postTypes" v-bind:value="option.id" :key="option">{{ option.name }}</option>
        </select>
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-2 control-label">入职时间</label>
      <div class="col-sm-4">
        <MyDatePicker v-bind:date='queryData.entryFrom' @timeChanged="time => this.queryData.entryFrom = time" ref="entryFrom"></MyDatePicker>
      </div>
      <label class="col-sm-2 control-label">到</label>
      <div class="col-sm-4">
        <MyDatePicker v-bind:date='queryData.entryTo' @timeChanged="time => this.queryData.entryTo = time" ref="entryTo"></MyDatePicker>
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-2 control-label">职务</label>
      <div class="col-sm-4">
        <multiselect v-model="queryData.positions" :options="positions" :multiple="true" :close-on-select="false" :clear-on-select="false" :hide-selected="true" :preserve-search="true" select-label="请点击选择" placeholder="请选择职务(可多选)" label="language" track-by="name">
          <template slot="tag" scope="props">
            <span class="custom__tag">
              <span>{{ props.option.language }}</span>
              <span class="custom__remove" @click="props.remove(props.option)">❌</span>
            </span>
          </template>
        </multiselect>
      </div>
      <label class="col-md-2 control-label my-label">来源渠道</label>
      <div class="col-sm-4">
        <Channel ref='channel' :withUnlimit='true' :selectedChannel='queryData.channel' @channelchanged="val => queryData.channel = val"></Channel>
      </div>
    </div>
    <!--<div class="form-group">
       <label class="col-sm-2 control-label">学位</label>
      <div class="col-sm-4">
        <select class="form-control" v-model="queryData.degree">
          <option v-for="option in this.degrees" v-bind:value="option.id">{{ option.name }}</option>
        </select>
      </div> 
    </div>
    <div class="form-group">
       <label class="col-sm-2 control-label">所学专业</label>
      <div class="col-sm-8">
        <input type="text" class="form-control" v-model="queryData.discipline" id="inputCert" placeholder="毕业专业信息">
      </div> 
    </div>-->
  </div>
</template>
<script>
import Multiselect from 'vue-multiselect'
import MyDatePicker from '../../mycomponents/common/MyDatePicker'
import Depart from '../../mycomponents/common/Depart'
import National from '../../mycomponents/common/National'
import Channel from '../../mycomponents/common/Channel'
import Birthplace from '../../mycomponents/common/Birthplace'
import WorkType from '../../mycomponents/common/WorkType'
import EmployeeStatus from '../../mycomponents/common/EmployeeStatus'
import Policy from '../../mycomponents/common/Policy'
export default {
  "name": "OnJobUserQuery",
  components: {
    Depart,
    Multiselect,
    MyDatePicker,
    National,
    Birthplace,
    Channel,
    WorkType,
    EmployeeStatus,
    Policy
  },
  props: ['data'],
  data: function() {
    return {
      queryData: {
        phone:'',
        tel:'',
        depart: null,
        name: null,
        idCard: null,
        national: -1,
        birtFrom: '',
        birtTo: '',
        entryFrom:'',
        entryTo:'',
        birthplace: {
          province: -1,
          city: -1
        },
        sex: -1,
        workage: -1,
        postType: -1,
        empState: 1,
        positionlevel: -1,
        discipline: null,
        degree: -1,
        workType: -1,
        channel: -1,
        positions:null
      },
      postTypes: [{ id: -1, name: '不限' }],
      positionlevels: [{ id: -1, name: '不限' }],
      degrees: [{ id: -1, name: '不限' }],
      positions: [{ id: -1, name: '不限' }]

    }
  },
  created: function() {
    this.postTypes = this.postTypes.concat(this.$store.state.sysconfigs.postTypes)
    this.positionlevels = this.positionlevels.concat(this.$store.state.sysconfigs.positionlevels)
    this.degrees = this.degrees.concat(this.$store.state.sysconfigs.FtEducation)
    this.positions = this.positions.concat(this.$store.state.sysconfigs.positions)
  },
  methods: {
    getData() {

      var newQueryData = []

      // 单位
      if (this.queryData.depart != null && this.queryData.depart.length > 0) {
        newQueryData.push({
          field: "departmentId",
          op: "=",
          value: this.queryData.depart[this.queryData.depart.length - 1]
        })
      }

      // 名称
      if (this.queryData.name) {
        newQueryData.push({
          field: "name",
          op: "like",
          value: '%'+this.queryData.name+'%'
        })
      }

      // 证明
      if (this.queryData.idCard) {
        newQueryData.push({
          field: "idCard",
          op: "like",
          value: '%'+this.queryData.idCard+'%'
        })
      }

      // 民族
      if (this.queryData.national != -1) {
        newQueryData.push({
          field: "nation",
          op: "=",
          value: this.queryData.national
        })
      }

      // 生日
      if (this.queryData.birtFrom != '') {
        newQueryData.push({
          field: "birthday",
          op: ">=",
          value: this.queryData.birtFrom
        })
      }
      
      // 生日
      if (this.queryData.birtTo != '') {
        newQueryData.push({
          field: "birthday",
          op: "<",
          value: this.queryData.birtTo
        })
      }

      // 入职时间
      if (this.queryData.entryFrom != '') {
        newQueryData.push({
          field: "createTime",
          op: ">=",
          value: this.queryData.entryFrom
        })
      }

      // 入职时间
      if (this.queryData.entryTo != '') {
        newQueryData.push({
          field: "createTime",
          op: "<",
          value: this.queryData.entryTo
        })
      }

      // 籍贯
      if (this.queryData.birthplace.province != -1 && this.queryData.birthplace.city != -1) {
        newQueryData.push({
          field: "nativePlace",
          op: "=",
          value: this.queryData.birthplace.province + '%' + this.queryData.birthplace.city
        })
      }

      // 性别
      if (this.queryData.sex != -1) {
        newQueryData.push({
          field: "sex",
          op: "=",
          value: this.queryData.sex
        })
      }

      // 工作类型
      if (this.queryData.workType != -1) {
        newQueryData.push({
          field: "workerType",
          op: "=",
          value: this.queryData.workType
        })
      }

      // 在职状态
      if (this.queryData.empState != -1) {
        newQueryData.push({
          field: "state",
          op: "=",
          value: this.queryData.empState
        })
      }

      // 来源
      if (this.queryData.channel != -1) {
        newQueryData.push({
          field: "source",
          op: "=",
          value: this.queryData.channel
        })
      }

      // 移动电话
      if (this.queryData.phone != ''){
        newQueryData.push({
          field: "phone",
          op: "like",
          value: '%'+this.queryData.phone+'%'
        })
      }

      // 办公电话
      if (this.queryData.tel != ''){
        newQueryData.push({
          field: "tel",
          op: "like",
          value: '%'+this.queryData.tel+'%'
        })
      }

      // 岗位
      if( this.queryData.postType != -1){
        newQueryData.push({
          field: "gwType",
          op: "=",
          value: this.queryData.postType
        })
      }

      // 职务
      if (this.queryData.positions != null && this.queryData.positions.length >0) {
        var positions = null
        for (var pos in this.queryData.positions) {
        if (!positions) {
          positions = this.queryData.positions[pos].name
        }
        else
            positions = positions + ',' + this.queryData.positions[pos].name
        }
        newQueryData.push({
          field: "positions",
          op: "=",
          value: positions
        })
      }

      return newQueryData
    }
  }
}
</script>

